<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        function Persion(name, age, gender) {
            this.name = name;
            this.age = age;
            this.gender = gender;
        }

        var per1 = new Persion("张三", 18, "男");
        var per2 = new Persion("李四", 18, "男");


        //将sayName方法在Persion的原型对象中定义
        Persion.prototype.toString = function () {
            return "Persion[name=" + this.name + ",age=" + this.age + ",gender=" + this.gender + "]"
            // return "我是一个a"
        }

        //这样的话只是针对per1对象，想要公共使用的话，放到原型对象中
        // per1.toString = function(){
        //     return "Persion[name="+this.name+",age="+this.age+",gender="+this.gender+"]"
        //     // return "我是一个a"
        // }


        var result = per1.toString()

        console.log(result)

        console.log(per1)
        console.log(per2)

        console.log(per1.toString())  //输出：Persion[name=张三,age=18,gender=男]
        console.log(per2.toString())
    </script>


</head>
<body>

</body>
</html>
